import { Controller } from "../../mvc/core/Controller";
import { ViewEvent } from "../../mvc/events/ViewEvent";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { LanternRiddlesPanel } from "../view/activity/lanternRiddles/LanternRiddlesPanel";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SQuestionBossInfo } from "../../../Message/Public/SQuestionBossInfo";
import { IView } from "../../mvc/interfaces/IView";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
//class LanternRiddlesController
    
    export  class LanternRiddlesController extends Controller
    {
       

        /* internal  */addListener(arg1: ViewEvent): void
        {
            Dispatcher.addEventListener(EventName.ChangeScene, this.onChangeScene);
            return;
        }

        /* internal  */removeListener(arg1: ViewEvent): void
        {
            Dispatcher.removeEventListener(EventName.ChangeScene, this.onChangeScene);
            return;
        }

        /* internal  */onChangeScene(arg1: DataEvent): void
        {
            if (_view && !_view.isHide) 
            {
                LanternRiddlesPanel(view).hide();
            }
            return;
        }

        /* internal  */onQuestionBossInfo(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SQuestionBossInfo;
            if (loc1) 
            {
                if (_view == null || _view && _view.isHide) 
                {
                    LanternRiddlesPanel(view).show();
                    LanternRiddlesPanel(view).updatePosition();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.TaskTrackShowOrHide, false));
                }
                LanternRiddlesPanel(view).tfLeftTime = loc1.remainTime;
                LanternRiddlesPanel(view).rightNum = loc1.rightNumber;
                LanternRiddlesPanel(view).awardList = loc1.awardMap;
            }
            else if (_view && !_view.isHide) 
            {
                LanternRiddlesPanel(view).hide();
            }
            return;
        }

        protected /* override */ initView(): IView
        {
            if (this._lanternRiddlesPanel == null) 
            {
                this._lanternRiddlesPanel = new LanternRiddlesPanel();
                this._lanternRiddlesPanel.addEventListener(ViewEvent.Show, this.addListener);
                this._lanternRiddlesPanel.addEventListener(ViewEvent.Hide, this.removeListener);
            }
            return this._lanternRiddlesPanel;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicQuestionBossInfo, this.onQuestionBossInfo);
            return;
        }

        private /* var */_lanternRiddlesPanel: LanternRiddlesPanel;
    }
